<template>
  <div>
    <van-nav-bar
      title="找回密码"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-form @submit="onSubmit">
      <van-field
        v-model="userInfo.mobile"
        type="text"
        name="手机号"
        placeholder="请输入手机号"
        :rules="[{ required: true, message: '请填写手机号' }]"
      />
      <van-field
        v-model="userInfo.sms_code"
        center
        clearable
        placeholder="请输入验证码"
      >
        <template #button>
          <span
            v-show="sendAuthCode"
            class="auth_text auth_text_blue"
            @click="getAuthCode"
            >获取验证码</span
          >
          <span v-show="!sendAuthCode" class="auth_text">
            <span class="auth_text_blue">{{ auth_time }} </span>
            秒之后重新发送验证码</span
          >
        </template>
      </van-field>
      <van-field
        v-model="userInfo.password"
        type="password"
        name="密码"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <van-button round block type="info" native-type="submit">
        登录
      </van-button>
    </van-form>
  </div>
</template>

<script>
import { lzGetSMS, lzpassword } from "../../utils/http";
export default {
  name: "",
  components: {},
  props: [],
  data() {
    return {
      sendAuthCode: true /*布尔值，通过v-show控制显示‘获取按钮’还是‘倒计时’ */,
      auth_time: 0 /*倒计时 计数器*/,
      userInfo: {
        mobile: "19801237380",
        password: "",
        sms_code: "",
        sms_type: "getPassword",
        type: 1,
        client: 1,
      },
    };
  },
  mounted() {},
  methods: {
    onClickLeft() {
      this.$router.push("/login");
    },
    async onSubmit(values) {
        console.log(values)
      const res = await lzpassword(this.userInfo);
      console.log(res);
      sessionStorage.getItem('user',JSON.stringify(values))
      this.$router.push('/login')
    },


    async getAuthCode() {
      //发送验证码
      const res = await lzGetSMS(this.userInfo);
      console.log(res);

      //验证码倒计时
      this.sendAuthCode = false;
      this.auth_time = 30;
      var auth_timetimer = setInterval(() => {
        this.auth_time--;
        if (this.auth_time <= 0) {
          this.sendAuthCode = true;
          clearInterval(auth_timetimer);
        }
      }, 1000);
    },
  },
  computed: {},
  watch: {},
  created() {},
};
</script>

<style scoped>
</style>
